<?php

namespace Frame\LLOneBot;
use app\core\App;

class Response
{

    /**
     * 发送信息
     * @param mixed $post
     * @return bool|string
     */
    public static function sendMsg($post)
    {

        return self::sendPost('/send_msg',$post);
    }

    /**
     * 发送json消息
     * @param mixed $post
     */
    public static function sendJson($post)
    {
        


    }



    public static function sendPost($url, $data)
    {
        print_r($data);
        $url = App::_getFrameConfig()['http_url'] . $url;
        file_put_contents(__DIR__.'/Send.log',"地址；{$url}\n内容；{".json_encode($data)."}\n",FILE_APPEND);

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HTTPHEADER, [
            'Content-Type: application/json'
        ]);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $result = curl_exec($ch);
        curl_close($ch);
        file_put_contents(__DIR__.'/Send.log',"响应；{$result}\n\n",FILE_APPEND);
        print_r($result);
        return $result;
    }
}